<template>
  <div>
    <index-njt v-if='isShow' :title='title' />
  </div>
</template>

<script>
import IndexNjt from "@/views/IndexNjt.vue";
import {getAction} from "@/utils/axiosUtils";

export default {
  name: 'index',
  components: {IndexNjt},
  data() {
    return {
      //首页标题
      title:null,
      isShow:false,
      url:{
        index:'/njt/index/hasIndexAuth',
      }
    }
  },
  created() {
    this.initIndex()
  },
  methods: {
    //根据登录用户判断权限,展示不同页面
    async initIndex(){
      try {
        let res = await getAction(this.url.index)
        let {code, data: {hasIndex, title}} = res
        if (code === 200) {
          //判断是否加载首页
          if (hasIndex) {
            //设置首页标题
            this.title = title
          } else {
            //判断是否是监管者
            //跳转到合格证打印记录
            await this.$router.push('/certificate/certificate')
          }
        }
      } catch (e) {
        console.log("获取首页权限异常",e)
      } finally {
        this.isShow = true
      }
    },
  }
}
</script>
<style lang="scss" scoped>

</style>
